package com.ask.ff.upload_server.controller;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MaxUploadSizeExceededException;

import java.util.HashMap;

@ControllerAdvice
public class FileUploadExceptionAdvice {

    @ResponseBody
    @ExceptionHandler(MaxUploadSizeExceededException.class)
    public Object fileUploadExceptionHandler(MaxUploadSizeExceededException exc) {
        // 响应数据
        HashMap<String, Object> responseData = new HashMap<>(); // 响应数据一层数据
        HashMap<String, String> responseDataInfo = new HashMap<>(); // 响应数据二层数据

        // 判断密钥是否准确（模拟）
        responseDataInfo.put("message", "上传文件不得超过 1M！");
        responseData.put("error", responseDataInfo);
        return responseData;
    }

}
